﻿/*                              
   Copyright 2011 Nils Kopal, Christopher Krüger, Simone Sauer, Dennis Nolte, Uni Duisburg-Essen

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

using System;
using System.Threading;
using Sharebert.OverlayLibrary.API;
using Sharebert.OverlayLibrary;
using Sharebert.LoggingLibrary;
using Sharebert.LoggingLibrary.API;

namespace Sharebert.OverlayLibraryDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().StartClient();
            Console.ReadLine();
        }

        // Just for testing purposes, feel free to edit
        private void StartClient()
        {
            ILogger logger = new Logbert();
            logger.MessageLogged += new EventHandler<LogEventArgs>(HandleLogMessage);

            IOverlay overlay = new Overlay("134.91.78.68", 4000, "0.0.0.0", logger);
            overlay.BootstrapServerIsDown += new EventHandler<EventArgs>(HandleBootstrapServerIsDown);
            overlay.Connect();
        }

        private void HandleBootstrapServerIsDown(object sender, EventArgs e)
        {
            Console.WriteLine("Could not open connection to bootstrap server");
        }

        private void HandleLogMessage(object sender, LogEventArgs e)
        {
            Console.WriteLine(String.Format("{0}: {1}", e.Type, e.Message));
            if (e.Error != null)
            {
                Console.WriteLine(e.Error);
            }
        }
    }
}
